#!/usr/bin/env ruby
#
#  Created by sjavey on 2007-07-07.
#  Copyright (c) 2007. All rights reserved.

require 'rexml/document'

module N19GPX
  class TrackPoint
  
    attr_reader :lat
    attr_reader :lon
    attr_reader :ele
    attr_reader :time
    attr_reader :pst_hour_minute
    attr_reader :gmt_offset
  
    def initialize(trackPoint)
      @gmt_offset = -7
      @lat = trackPoint.attribute("lat")
      @lon = trackPoint.attribute("lon")
      @ele = Float(trackPoint.elements["ele"].text)
      time = trackPoint.elements["time"].text
      @time = time ? time : ""
      @pst_hour_minute = ""
      if (@time != "")
        hour = @time[11..12].to_i + @gmt_offset
        minute = Float(@time[14..15].to_i / 60.0)
        @pst_hour_minute = sprintf("%.2f", hour + minute).to_f
      end  
    end
  
    def javascript
      str = <<EOS
    
    function N19_TrackPoint(latitude, longitude, elevation, time) {
      this.lat = latitude;
      this.lon = longitude;
      this.ele = elevation;
      this.time = time
    }
EOS
    end
  end
end